package api

import (
	"github.com/gin-gonic/gin"
	"main/api/handler"
	"main/api/middleware"
	"main/global"
	"main/pkg"
)

func Router(r *gin.Engine) {
	r.Use(middleware.RunTime())
	api := r.Group("/api")
	{
		user := api.Group("/user")
		{
			user.POST("/register", handler.RegisterUser)
			user.POST("/login", handler.LoginUser)
			user.Use(pkg.JWTAuth(global.JWT_SECRET_KEY))
			user.GET("/logout", handler.LogoutUser)
		}
		chat := api.Group("/chat")
		{
			chat.Use(pkg.JWTAuth(global.JWT_SECRET_KEY))
			chat.GET("/ws", handler.Ws)
		}
		article := api.Group("/article")
		{
			article.Use(pkg.JWTAuth(global.JWT_SECRET_KEY))
			article.POST("/add", handler.AddArticle)
			article.POST("/batch", handler.BatchArticle)
			article.POST("/update", handler.UpdateArticle)
			article.POST("/upload", handler.UploadArticle)
			article.POST("/remove", handler.RemoveArticle)
			article.GET("/detail", handler.DetailArticle)
		}
		gift := api.Group("/gift")
		{
			gift.Use(pkg.JWTAuth(global.JWT_SECRET_KEY))
			gift.POST("/add", handler.AddGift)
			gift.POST("/update", handler.UpdateGift)
			gift.POST("/remove", handler.RemoveGift)
			gift.POST("/list", handler.ListGift)

			gift.POST("/buy", handler.BuyGift)
			gift.POST("/send", handler.SendGift)
		}
	}
}
